import router from '@/router'
import { getShareToMyStatus } from '../../api/share'
// import { addversionHtml } from '../../api/file'

const state = {
  projectId: '',
  projectName: '',
  historyDialogVisible: false,
  authority: {},
  shareToMyStatus: 0,
  selectedFile: { suffix: '' },
  userInfo: {},
}

const mutations = {
  set_projectId(state, projectId) {
    state.projectId = projectId
  },
  set_projectName(state, projectName) {
    state.projectName = projectName
  },
  set_historyDialogVisible(state, type) {
    state.historyDialogVisible = type
  },
  set_authority(state, authority) {
    state.authority = authority
  },
  set_selectedFile(state, selectedFile) {
    state.selectedFile = selectedFile
  },
  set_userInfo(state, userInfo) {
      state.userInfo = userInfo
  }
}

const actions = {
  // user logout
  // logout({ commit, state, dispatch }) {
  logout() {
    sessionStorage.userInfo = ''
    sessionStorage.projectId = ''
    state.isLogin = false;
    state.userInfo = {};
    router.push(`/login`)
  },
  // addversionHtml({ commit, state, dispatch }, { fileid, html }) {
  //   MessageBox.prompt('', '版本命名', {
  //     confirmButtonText: '确定',
  //     cancelButtonText: '取消',
  //     closeOnClickModal: false,
  //     beforeClose: async(action, instance, done) => {
  //       if (action === 'confirm') {
  //         console.log(instance)
  //         instance.confirmButtonLoading = true
  //         instance.confirmButtonText = '执行中...'
  //         const name = instance.inputValue
  //         addversionHtml(fileid, html, name)
  //           .then(result => {
  //             // Message('保存成功')
  //               Vue.$toast('保存成功')
  //             instance.confirmButtonLoading = false
  //             done()
  //           })
  //           .catch(err => {
  //             console.log(err)
  //           })
  //       } else {
  //         done()
  //       }
  //     }
  //   })
  // },
  getShareToMyStatus({ commit, state }) {
    getShareToMyStatus()
      .then(result => {
        const { data } = result
        state.shareToMyStatus = data
        console.log(commit)
      })
      .catch(err => {
        console.log(err)
      })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
